import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import elib.Bibliotekarz;
import elib.Kierownik;
import elib.Osoba;

@WebServlet("/ShowWorkerServlet")
public class ShowWorkerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public ShowWorkerServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		HttpSession session = request.getSession();
		List<Bibliotekarz> listaPracownikow = null;
		if (session != null) {
			Osoba osoba = (Osoba) session.getAttribute("osoba");
			if (osoba != null && osoba instanceof Kierownik) {
				listaPracownikow = ((Kierownik) osoba).wypiszPracownikow();
				session.setAttribute("pracownicy", listaPracownikow);
				response.sendRedirect("admin.jsp?page=workers");
			} else
				response.sendRedirect("index.jsp");
		} else
			response.sendRedirect("index.jsp");
		out.close();
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
}